package com.system.healthproject.service.imp;

import com.system.healthproject.mapper.*;
import com.system.healthproject.model.admin.paramsbean.AbnormalEEGParams;
import com.system.healthproject.model.admin.paramsbean.DiseaseOnsetParams;
import com.system.healthproject.model.admin.paramsbean.DrugParams;
import com.system.healthproject.model.admin.paramsbean.SymptomParams;
import com.system.healthproject.pojo.*;
import com.system.healthproject.service.CommonParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommonParamsServiceImp implements CommonParamsService {

    @Autowired
    SymptomMapper symptomMapper;
    @Autowired
    SymptomTypeMapper symptomTypeMapper;
    @Autowired
    DiseaseOnsetMapper diseaseOnsetMapper;
    @Autowired
    DiseaseOnsetTypeMapper diseaseOnsetTypeMapper;
    @Autowired
    AbnormalEEGMapper abnormalEEGMapper;
    @Autowired
    AbnormalEEGTypeMapper abnormalEEGTypeMapper;
    @Autowired
    DrugMapper drugMapper;
    @Autowired
    DrugTypeMapper drugTypeMapper;
    @Autowired
    CtMapper ctMapper;
    @Autowired
    OperationMapper operationMapper;
    @Autowired
    ChronicMapper chronicMapper;
    @Autowired
    InheritanceMapper inheritanceMapper;

    /**
     * 添加诊断症状
     * @param symptom
     * @return
     */
    @Override
    public boolean addSymptom(SymptomParams symptom) {
        Symptom record = new Symptom();
        record.setSymptomName(symptom.getSymptomName());
        record.setSymptomtypeId(symptom.getSymptomtypeId());
        int insert = symptomMapper.insert(record);
        return insert==1;
    }

    /**
     * 添加诊断症状类型
     * @param symptomType
     * @return
     */
    @Override
    public boolean addSymptomType(String symptomType) {
        SymptomType record = new SymptomType();
        record.setSymptomtypeName(symptomType);
        int insert = symptomTypeMapper.insert(record);
        return insert==1;
    }

    /**
     * 获取症状类型
     * @return
     */
    @Override
    public List<SymptomType> symptomTypeList() {
        List<SymptomType> symptomTypes = symptomTypeMapper.symptomTypeList();
        return symptomTypes;
    }

    /*
     * 根据类型id获取症状列表
    * @param typeId
     * @return
     */
    @Override
    public List<Symptom> symptomListByType(Integer typeId) {
        List<Symptom> symptoms = symptomMapper.symptomListByType(typeId);
        return symptoms;
    }

    /**
     * 添加综合症
     * @param diseaseOnsetParams
     * @return
     */
    @Override
    public boolean addDiseaseOnset(DiseaseOnsetParams diseaseOnsetParams) {
        DiseaseOnset record = new DiseaseOnset();
        record.setDiseaseonsetName(diseaseOnsetParams.getDiseaseonsetName());
        record.setDiseaseonsettypeId(diseaseOnsetParams.getDiseaseonsettypeId());
        int insert = diseaseOnsetMapper.insert(record);
        return insert==1;
    }

    /**
     * 添加综合症类型
     * @param diseaseonsettypeName
     * @return
     */
    @Override
    public boolean addDiseaseOnsetType(String diseaseonsettypeName) {
        DiseaseOnsetType record = new DiseaseOnsetType();
        record.setDiseaseonsettypeName(diseaseonsettypeName);
        record.setCreatetime(new Date());
        int insert = diseaseOnsetTypeMapper.insert(record);
        return insert==1;
    }

    /**
     * 删除综合症类型
     * @param diseaseonsettypeId
     * @return
     */
    @Override
    public boolean deleteDiseaseOnsetType(Integer diseaseonsettypeId) {
        Integer integer = diseaseOnsetMapper.selectCountByTypeId(diseaseonsettypeId);
        if(integer>0){
            return false;
        }
        return diseaseOnsetTypeMapper.deleteByPrimaryKey(diseaseonsettypeId)==1;
    }

    /**
     * 根据类型获取综合症列表
     * @param typeId
     * @return
     */
    @Override
    public List<DiseaseOnset> diseaseOnsetListByType(Integer typeId) {
        List<DiseaseOnset> diseaseOnsets = diseaseOnsetMapper.selectListByTypeId(typeId);
        return diseaseOnsets;
    }

    /**
     * 获取综合症类型列表
     * @return
     */
    @Override
    public List<DiseaseOnsetType> diseaseOnsetTypeList() {
        List<DiseaseOnsetType> diseaseOnsetTypes = diseaseOnsetTypeMapper.selectList();
        return diseaseOnsetTypes;
    }

    /**
     * 添加脑电图异常
     * @param abnormalEEGParams
     * @return
     */
    @Override
    public boolean addEEG(AbnormalEEGParams abnormalEEGParams) {
        AbnormalEEG record = new AbnormalEEG();
        record.setAbnormaleegContent(abnormalEEGParams.getAbnormaleegContent());
        record.setAbnormaleegtypeId(abnormalEEGParams.getAbnormaleegtypeId());
        int insert = abnormalEEGMapper.insert(record);
        return insert==1;
    }

    /**
     * 添加脑电图异常类型
     * @param abnormaleegtypeName
     * @return
     */
    @Override
    public boolean addEEGType(String abnormaleegtypeName) {
        AbnormalEEGType record = new AbnormalEEGType();
        record.setAbnormaleegtypeName(abnormaleegtypeName);
        int insert = abnormalEEGTypeMapper.insert(record);
        return insert==1;
    }

    @Override
    public boolean deleteEEGType(Integer abnormaleegtypeId) {
        Integer integer = abnormalEEGMapper.selectCountByTypeId(abnormaleegtypeId);
        if(integer>0){
            return false;
        }
        int i = abnormalEEGTypeMapper.deleteByPrimaryKey(abnormaleegtypeId);
        return i==1;
    }

    /**
     * 根据脑电图异常类型id获取脑电图异常
     * @param typeId
     * @return
     */
    @Override
    public List<AbnormalEEG> eeGListByType(Integer typeId) {
        List<AbnormalEEG> abnormalEEGS = abnormalEEGMapper.selectListByTypeId(typeId);
        return abnormalEEGS;
    }

    /**
     * 获取脑电图异常
     * @return
     */
    @Override
    public List<AbnormalEEGType> eeGTypeList() {
        List<AbnormalEEGType> abnormalEEGTypes = abnormalEEGTypeMapper.selectList();
        return abnormalEEGTypes;
    }

    /**
     * 添加药瓶
     * @param drugParams
     * @return
     */
    @Override
    public boolean addDrug(DrugParams drugParams) {
        Drug record = new Drug();
        record.setDrugName(drugParams.getDrugName());
        record.setDrugtypeId(drugParams.getDrugtypeId());
        int insert = drugMapper.insert(record);
        return insert==1;
    }

    /**
     * 添加药瓶类型
     * @param drugtypeName
     * @return
     */
    @Override
    public boolean addDrugType(String drugtypeName) {
        DrugType record = new DrugType();
        record.setDrugtypeName(drugtypeName);
        int insert = drugTypeMapper.insert(record);
        return insert==1;
    }

    @Override
    public boolean deleteDrugType(Integer drugtypeId) {
        Integer integer = drugMapper.selectCountByTypeId(drugtypeId);
        if(integer>0){
            return false;
        }

        return drugTypeMapper.deleteByPrimaryKey(drugtypeId)==1;
    }

    /**
     * 获取药瓶类型
     * @return
     */
    @Override
    public List<DrugType> DrugTypeList() {
        List<DrugType> drugTypes = drugTypeMapper.selectList();
        return drugTypes;
    }

    /**
     * 根据药瓶类型id获取药瓶列表
     * @param typeId
     * @return
     */
    @Override
    public List<Drug> drugListByTypeId(Integer typeId) {
        List<Drug> drugs = drugMapper.selectListByTypeId(typeId);
        return drugs;
    }

    /**
     * 添加异常
     * @param ctName
     * @return
     */
    @Override
    public boolean addCt(String ctName) {
        Ct record = new Ct();
        record.setMagneticName(ctName);
        int insert = ctMapper.insert(record);
        return insert==1;
    }

    /**
     * 获取CT异常列表
     * @return
     */
    @Override
    public List<Ct> ctList() {
        List<Ct> ctList = ctMapper.selectList();
        return ctList;
    }

    /**
     * 添加手术
     * @param operationName
     * @return
     */
    @Override
    public boolean addOperation(String operationName) {
        Operation record = new Operation();
        record.setOperationName(operationName);
        int insert = operationMapper.insert(record);
        return insert==1;
    }

    /**
     *获取手术列表
     * @return
     */
    @Override
    public List<Operation> operationList() {
        List<Operation> operations = operationMapper.selectList();
        return operations;
    }

    /**
     * 添加慢病史
     * @param chronicName
     * @return
     */
    @Override
    public boolean addChronic(String chronicName) {
        Chronic record = new Chronic();
        record.setChronicName(chronicName);
        int insert = chronicMapper.insert(record);
        return insert == 1;
    }

    /**
     * 获取慢病史列表
     * @return
     */
    @Override
    public List<Chronic> chronicList() {
        List<Chronic> chronics = chronicMapper.selectList();
        return chronics;
    }

    /**
     * 添加家族病史
     * @param chronicName
     * @return
     */
    @Override
    public boolean addInheritance(String chronicName) {
        Inheritance record = new Inheritance();
        record.setInheritanceName(chronicName);
        int insert = inheritanceMapper.insert(record);
        return insert==1;
    }

    @Override
    public List<Inheritance> inheritanceList() {
        List<Inheritance> inheritances = inheritanceMapper.selectList();
        return inheritances;
    }

    @Override
    public boolean deleteSymptom(Integer id) {
        return symptomMapper.deleteByPrimaryKey(id)==1;
    }

    @Override
    public boolean deleteSymptomType(Integer id) {
        Integer integer = symptomMapper.symptomCountByType(id);
        if(integer>0){
            return false;
        }
        return symptomTypeMapper.deleteByPrimaryKey(id)==1;
    }

    @Override
    public boolean deleteDiseaseOnset(Integer id) {
        return diseaseOnsetMapper.deleteByPrimaryKey(id)==1;
    }

    @Override
    public boolean deleteEEg(Integer eegId) {
        int i = abnormalEEGMapper.deleteByPrimaryKey(eegId);
        return i==1;
    }

    @Override
    public boolean deleteDrug(Integer drugId) {
        int i = drugMapper.deleteByPrimaryKey(drugId);
        return i==1;
    }

    @Override
    public boolean deleteCt(Integer ctId) {
        int i = ctMapper.deleteByPrimaryKey(ctId);
        return i==1;
    }

    @Override
    public boolean deleteOperation(Integer operationId) {
        int i = operationMapper.deleteByPrimaryKey(operationId);
        return i==1;
    }

    @Override
    public boolean deleteChronic(Integer chronicId) {
        int i = chronicMapper.deleteByPrimaryKey(chronicId);
        return i ==1;
    }

    @Override
    public boolean deleteInheritance(Integer inheritanceId) {
        int i = inheritanceMapper.deleteByPrimaryKey(inheritanceId);
        return i ==1;
    }


}
